#include <stdio.h>
#include "util/hex_util.h"
#include <unistd.h>
#include <string.h>

int main(int argc, char **argv) {
    char hex_buf[64] = { 0x00 };
    char bin_buf[64] = { 0x00 };
    const char *bin = "ABC秀杰123@#";
    uint32_t buf_len =  64;
    printf("len = %lu bin = %s\n", strlen(bin), bin);
    printf("bin str_is_hex = %d\n", str_is_hex(bin, strlen(bin)));

    int ret = encode_hex((uint8_t *)bin, strlen(bin), hex_buf, &buf_len, 1);
    if (ret != 0) {
        printf("encode_hex failed\n");
        return -1;
    }
    printf("len = %d hex = %s\n", buf_len, hex_buf);
    printf("hex str_is_hex = %d\n", str_is_hex(hex_buf, buf_len));
    buf_len =  64;
    ret = decode_hex(hex_buf, strlen(hex_buf), (uint8_t *)bin_buf, &buf_len);
    if (ret != 0) {
        printf("decode_hex failed\n");
        return -1;
    }
    printf("len = %d bin = %s\n", buf_len, bin_buf);

    memset(hex_buf, 0x00, sizeof(hex_buf));
    memset(bin_buf, 0x00, sizeof(bin_buf));
    buf_len =  64;
    ret = encode_hex((uint8_t *)bin, strlen(bin), hex_buf, &buf_len, 0);
    if (ret != 0) {
        printf("encode_hex failed\n");
        return -1;
    }
    printf("len = %d hex = %s\n", buf_len, hex_buf);
    printf("hex str_is_hex = %d\n", str_is_hex(hex_buf, buf_len));
    buf_len =  64;
    ret = decode_hex(hex_buf, strlen(hex_buf), (uint8_t *)bin_buf, &buf_len);
    if (ret != 0) {
        printf("decode_hex failed\n");
        return -1;
    }
    printf("len = %d bin = %s\n", buf_len, bin_buf);

    return 0;
}